<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/WEB-INF/template/globalTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:t="http://myfaces.apache.org/tomahawk"
                xmlns:opif="http://www.opif.com/formathlon/jsf/tags">

    <ui:define name="title">#{msg['application.titre.gestion.formation']}</ui:define>
    
    <ui:define name="ariane">
        <h:commandLink action="/faces/index.xhtml"
                       value="#{msg['application.titre.accueil']}"  />
        >
        
        #{msg['application.titre.gestion.formation']}
    </ui:define>

    
    <ui:define name="content">
        <h:panelGroup styleClass="titre">Liste des formations</h:panelGroup>
        <p:commandLink styleClass="lienAction lienCreer"
                       value="#{msg['application.creer']} une formation"
                       action="#{gestFormationBean.creer()}"
                       update="popup"  />
        <p:dataTable value="#{gestFormationBean.listFormation}" var="formation" id="dataTableListeFormation"
                      emptyMessage="#{msg['application.emptyMessage']}">
            <p:column headerText="ID" style="text-align: center">
                <h:outputText value="#{formation.id}" style="text-align: center"/>
            </p:column>
            <p:column headerText="Domaine">
                <h:outputText value="#{formation.domaine.libelle}" style="text-align: center"/>
            </p:column>
            <p:column headerText="Intitule">
                <h:outputText value="#{formation.libelle}" style="text-align: center"/>
            </p:column>
            <p:column headerText="Instructeurs">
                <h:outputText value="#{formation.listInstructeur.size()}" style="text-align: center"/>
            </p:column>
            <p:column headerText="Séances">
                <h:outputText value="#{gestFormationBean.nombre(formation)} (#{gestFormationBean.duree(formation)}h)"
                              style="text-align: center"/>
            </p:column>
            <p:column headerText="Période">
                <h:outputText value="#{formation.dateDebut}" style="text-align: center">
                    <f:convertDateTime pattern="dd/MM/yy"/>
                </h:outputText>
                <h:outputText value="#{formation.dateFin}" style="text-align: center">
                    <f:convertDateTime pattern=" - dd/MM/yy"/>
                </h:outputText>
            </p:column>
            <p:column headerText="Actions">
                <p:commandLink action="#{gestFormationBean.modifier(formation)}"
                               value="Modifier"
                               update="globalForm:popup"  />
                &nbsp;
                <p:commandLink action="#{gestFormationBean.supprimer(formation)}"
                               value="Supprimer"
                               update="globalForm:confirm"  />
            </p:column>
        </p:dataTable>
        <p:commandLink styleClass="lienAction lienCreer"
                       value="#{msg['application.creer']} une formation"
                       action="#{gestFormationBean.creer()}"
                       update="popup"  />
    </ui:define>
    
    <ui:define name="popup">
        <t:panelGrid columns="3">
            <h:outputLabel for="inputDomaine" value="Domaine"/>
            <p:selectOneMenu value="#{gestFormationBean.formation.domaine}"
                             converter="#{genericConverter}" id="inputDomaine"
                              >
               <f:selectItem itemDisabled="true" itemLabel="Choisir un domaine ..." />
               <f:selectItems value="#{gestFormationBean.listDomaine}" var="domaine" itemLabel="#{domaine.libelle}" />
            </p:selectOneMenu>
            <p:message for="inputDomaine"/>
            
            <h:outputLabel for="inputIntitule" value="Intitule"/>
            <p:inputText value="#{gestFormationBean.formation.libelle}" id="inputIntitule"
                          />
            <p:message for="inputIntitule"/>
            
            <h:outputLabel for="inputDescription" value="Description"/>
            <p:inputTextarea value="#{gestFormationBean.formation.description}" id="inputDescription"/>
            <p:message for="inputDescription"/>
            
            <t:panelGroup colspan="3">
                <h:outputLabel for="inputComplementaire">
                    <h:selectBooleanCheckbox value="#{gestFormationBean.formation.complementaire}"
                                             id="inputComplementaire"/>
                    Cette formation est une formation complémentaire.
                </h:outputLabel>
            </t:panelGroup>
            
            <h:outputLabel for="inputDateDebut" value="Début"/>
            <p:calendar value="#{gestFormationBean.formation.dateDebut}" id="inputDateDebut"
                        pattern="dd/MM/yyyy"  >
                <p:ajax event="dateSelect" listener="#{gestFormationBean.verifDateDebut}" update="messages" />
            </p:calendar>
            <p:message for="inputDateDebut"/>
            
            <h:outputLabel for="inputDateFin" value="Fin"/>
            <p:calendar value="#{gestFormationBean.formation.dateFin}"
                        id="inputDateFin" pattern="dd/MM/yyyy">
                <p:ajax event="dateSelect" listener="#{gestFormationBean.verifDateFin}" update="messages" />
            </p:calendar>
            <p:message for="inputDateFin"/>
            
            <t:panelGroup colspan="3">
                Liste des formateurs avancés pouvant dispenser cette formation :
                <p:pickList value="#{gestFormationBean.pickListInstructeur}"
                            var="instructeur" itemLabel="#{instructeur}"  
                            itemValue="#{instructeur}" addAllLabel="Remplir"
                            addLabel="Ajouter" removeAllLabel="Vider"
                            removeLabel="Retirer" converter="#{genericConverter}"/>
            </t:panelGroup>
            
            <t:panelGroup colspan="3" id="listeSeances">
                Liste des séances nécessaires à la formation :
                <p:dataTable value="#{gestFormationBean.formation.listSeanceTh}" var="seance" emptyMessage="#{msg['application.emptyMessage']}">
                    <p:column headerText="Nombre">
                        <p:spinner value="#{seance.nombre}" min="1"/>
                    </p:column>
                    <p:column headerText="Durée">
                        <p:spinner value="#{seance.duree}" min="1" max="8" suffix=" h."/>
                    </p:column>
                    <p:column headerText="Action">
                        <p:commandLink action="#{gestFormationBean.supprimerSeance(seance)}"
                                       value="Supprimer"
                                       update="globalForm:listeSeances"
                                       rendered="#{gestFormationBean.seanceSupprimable()}"/>
                    </p:column>
                </p:dataTable>
                
                <p:commandLink styleClass="lienAction lienCreer"
                               value="Ajouter"
                               action="#{gestFormationBean.ajouterSeance()}"
                               update="globalForm:listeSeances"/>
            </t:panelGroup>
        </t:panelGrid >
        
        <opif:validationButton managedBean="#{gestFormationBean}"
                               libelleValidation="Créer"
                               actionValidation="validerCreer"
                               onclick="popup.hide()"
                               update="dataTableListeFormation messages"
                               rendered="#{gestFormationBean.modeCreation}"/>
        
        <opif:validationButton managedBean="#{gestFormationBean}"
                               libelleValidation="Modifier"
                               actionValidation="validerModifier"
                               onclick="popup.hide()"
                               update="dataTableListeFormation messages"
                               rendered="#{!gestFormationBean.modeCreation}"/>
    </ui:define>
</ui:composition>
